package com.example.devclient;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class LoginActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login);
		
		findViews();
		setListeners();
	}
	
	private EditText fieldIP;
	private EditText fieldPort;
	private EditText fieldUser;
	private EditText fieldPwd;
	private Button btnLogin;
	private Button btnRet;
	
	
	private void findViews()
	{
		fieldIP = (EditText)findViewById(R.id.ipaddr);
		fieldPort = (EditText)findViewById(R.id.port);
		fieldUser = (EditText)findViewById(R.id.username);
		fieldPwd = (EditText)findViewById(R.id.password);
		btnLogin = (Button)findViewById(R.id.login);
		btnRet = (Button)findViewById(R.id.returnback);
		return;
	}
	
	private void setListeners()
	{
		btnLogin.setOnClickListener(login);
		btnRet.setOnClickListener(retback);
		return;
	}
	
	private Button.OnClickListener login = new Button.OnClickListener()
	{
		public void onClick(View v)
		{
			Intent intent = new Intent();
			intent.setClass(LoginActivity.this, PlayView.class);
			
			Bundle bundle = new Bundle();
			bundle.putString("KEY_IP", fieldIP.getText().toString());
			intent.putExtras(bundle);
			
			startActivity(intent);
		}
	};
	
	private Button.OnClickListener retback = new Button.OnClickListener()
	{
		public void onClick(View v)
		{
			finish();
		}
	};

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.login, menu);
		return true;
	}

}
